<?php

class m110922_035022_warehouse_in_manage extends CDbMigration {
	public function safeUp() {
		$this->addColumn('erp_user_access', 'materialWarehouseInboundManage', 'boolean');
		$this
			->insert('erp_auth_item',
				array(
					'name' => 'materialWarehouseInboundManage',
					'type' => CAuthItem::TYPE_ROLE,
					'bizrule' => 'return AccessControl::check("materialWarehouseInboundManage");',
				));
		$this
			->insert('erp_auth_item_child',
				array(
					'parent' => 'employee',
					'child' => 'materialWarehouseInboundManage',
				));

		$this->addColumn('erp_user_access', 'materialWarehouseInboundView', 'boolean');
		$this
			->insert('erp_auth_item',
				array(
					'name' => 'materialWarehouseInboundView',
					'type' => CAuthItem::TYPE_ROLE,
					'bizrule' => 'return AccessControl::check("materialWarehouseInboundView");',
				));
		$this
			->insert('erp_auth_item_child',
				array(
					'parent' => 'employee',
					'child' => 'materialWarehouseInboundView',
				));
	}

	public function safeDown() {
		$this
			->delete('erp_auth_item_child',
				array(
					'and',
					'parent=:parent',
					'child=:child',
				),
				array(
					':parent' => 'employee',
					':child' => 'materialWarehouseInboundManage',
				));
		$this
			->delete('erp_auth_item', 'name=:name',
				array(
					':name' => 'materialWarehouseInboundManage',
				));
		$this->dropColumn('erp_user_access', 'materialWarehouseInboundManage');

		$this
			->delete('erp_auth_item_child',
				array(
					'and',
					'parent=:parent',
					'child=:child',
				),
				array(
					':parent' => 'employee',
					':child' => 'materialWarehouseInboundView',
				));
		$this
			->delete('erp_auth_item', 'name=:name',
				array(
					':name' => 'materialWarehouseInboundView',
				));
		$this->dropColumn('erp_user_access', 'materialWarehouseInboundView');

	}
}
